<html>
<head>
    <title>登录界面</title>
    <script src="/js/jquery-3.3.1.min.js"></script>
</head>
<body>
登录<br>

用户名:<input type="text" id="username"/><br>
密码:<input type="password" id="password"/><br>
验证码:<input type="text" id="codeinput"><br>
<img id="code" src="/kaptcha/creat"/>
<br>
<button id="loginBtn"> 提交</button>

</body>
<script>
    $('#code').click(function () {
        $('#code').attr("src", "/kaptcha/creat");
    });
    $('#loginBtn').click(function () {
        $.ajax({
            type: "POST",
            async: true,
            url: "/login",
            data: JSON.stringify({
                "username": $('#username'),
                "password": $('#password'),
                "code": $('#codeinput')
            }),
            dataType: "json",
            success: function (data) {
                if (data.info == '欢迎登录') {
                    location.href = "/page/common/home";
                } else {
                    alert(data.info);
                    location.href = "/page/common/login";
                }
            },
            fail: function (data) {
                //ajax 失败执行
            }

        });
    });
</script>
</html>